class CourseController < ApplicationController

  def index
  end


  def new
    @course = Course.new
  end


  def create
    @course = Course.new(params[:course])
    
    if @course.save
      APPLOG.info 'Course #' + @course.id.to_s + ' ' + @course.name + ' added'
      flash[:notice] = 'Course successfully added into the database'
      redirect_to :action => 'list'
    else
      flash[:notice] = 'Course unsuccesfully added into the database'
      render :action => 'new'
    end
  end


  def edit
    @course = Course.get_by_id(params[:id])
  end


  def update
    @course = Course.get_by_id(params[:id])
    
    if @course.update_attributes(params[:course])
      APPLOG.info 'Course #' + @course.id.to_s + ' was updated'
      flash[:notice] = 'Course successfully updated'
      redirect_to :action => 'list'
    else
      flash[:notice] = 'Course unsuccessfully updated'
      render :action => 'edit'
    end
  end


  def list
    @courses = Course.get_all
  end


  def show
    @course = Course.get_by_id(params[:id])
  end


  def delete
    if Course.delete(params[:id])
      APPLOG.info 'Deleted course #' + params[:id].to_s
      redirect_to :action => 'index'
    else
      render :action => 'edit'
    end
  end
  
end
